package com.learn.aop.aspects;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


@Aspect
@Component
@Order(6)
public class LogAspect1 {


    @Pointcut(value = "execution(public * *..*.*(..))")
    public void mzyPointCut(){}

    @Pointcut(value = "execution(public * *..*Service.*(..))")
    public void transactionPointCut() {}
    @Before(value = "mzyPointCut()")
    public void beforeAdvice(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        System.out.println(signature.getName());
        System.out.println(signature.getDeclaringType());
        System.out.println(signature.getDeclaringTypeName());
        System.out.println(signature.getModifiers());

        System.out.println("aop前置通知");

    }

    @After("mzyPointCut()")
    public void afterAdvice() {
        System.out.println("aop后置通知");
    }

    @AfterReturning(
            value = "mzyPointCut()",
            returning = "afterReturningValue")
    public void afterReturn(Object afterReturningValue) {
        System.out.println("aop返回通知");

        System.out.println("返回值：" + afterReturningValue);
    }

    @AfterThrowing(
            value = "mzyPointCut()",
            throwing = "targetException"
    )
    public void afterThrowing(Throwable targetException) {

        targetException.printStackTrace();
        System.out.println("aop异常通知");
    }
}
